package com.example.translateappjava.Activity.HomeFragmentActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.translateappjava.Activity.MainActivity;
import com.example.translateappjava.R;

public class GoodResultActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Bitmap bitmap = null;
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_good_result);
        Intent intent = getIntent();
        byte[] byteArray = intent.getByteArrayExtra("bitmap");
        String scientificBasis = getIntent().getStringExtra("intakeSuggestion");
        String recognitionResult = getIntent().getStringExtra("recognitionResult");
        if (byteArray != null) {
            bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
            // 使用 bitmap
        }
        // 找到布局中的 TextView 并设置文本
        TextView textViewScientificBasis = findViewById(R.id.tv_mid2);
        textViewScientificBasis.setText("   "+scientificBasis+ "\n\n\n\n\n");
        @SuppressLint({"MissingInflatedId", "LocalSuppress"}) TextView fruitname = findViewById(R.id.tv_mid1);
        fruitname.setText(recognitionResult );
        if(bitmap != null){
            ImageView imageView = findViewById(R.id.iv_mid1);
            imageView.setImageBitmap(bitmap);
        }

//        setBackGroundColor(GoodResultActivity.this);

        findViewById(R.id.btn_exit2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });


    }

    /**
     * 设置返回逻辑
     */
    @Override
    public void onBackPressed() {
        super.onBackPressed();
        Intent intent = new Intent(GoodResultActivity.this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        finish(); // 结束当前 Activity
    }
}